/*
Miranda IM for Windows Search

Copyright (C) 2012 Nikolay Raspopov

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#pragma once

#pragma warning( disable : 4200 )	// "nonstandard extension used : zero-sized array in struct/union"

#pragma pack( push, 1 )

typedef struct
{
	time_t	tTimestamp;			// Contact last event time (current time if none)
	WCHAR	wszName[];			// Contact name (nick)
} ListData;

typedef struct
{
	DWORD	nFlags;				// Event flags 
	time_t	tTimestamp;			// Event timestamp
	WCHAR	wszText[];			// Event text
} EventData;

#pragma pack( pop )


BOOL Send(HANDLE hPipe, const void* pCommand, DWORD dwSize);
BOOL Recv(HANDLE hPipe, CAtlArray< BYTE >& pBuf);

inline BOOL Send(HANDLE hPipe, LPCSTR szCommand)
{
	return Send( hPipe, (const BYTE*)szCommand, (DWORD)strlen( szCommand ) );
}

inline BOOL Send(HANDLE hPipe, DWORD nCommand)
{
	return Send( hPipe, (const BYTE*)&nCommand, (DWORD)sizeof( nCommand ) );
}

inline BOOL Send(HANDLE hPipe, LPCWSTR szCommand)
{
	return Send( hPipe, (const BYTE*)szCommand, (DWORD)( wcslen( szCommand ) * sizeof( WCHAR ) ) );
}

inline BOOL Send(HANDLE hPipe, const CAtlArray< BYTE >& pCommand)
{
	return Send( hPipe, pCommand.GetData(), (DWORD)pCommand.GetCount() );
}

inline BOOL Command(HANDLE hPipe, LPCSTR szCommand, CAtlArray< BYTE >& pBuf)
{
	return Send( hPipe, szCommand ) && Recv( hPipe, pBuf );
}

extern PLUGININFOEX pluginInfo;	// Information about this plugin for Miranda IM
